/* eslint-disable react/prop-types */

import React from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';

import CastViewer from '../components/CastViewer';

import * as workAction from '../WorkAction';

connect(mapStateToProps, buildActionDispatcher)
export default class EmbedWorkDetailComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  exitFullScreen() {
    const { params, router } = this.props;
    router.push(`work/${params.workId}/detail`);
  }

  componentDidMount() {
    const { params, workAction } = this.props;
    workAction.getWorkDetail(params.workId).then((work) => {
      this.setState({ workInfo: work });
    });
  }

  render() {
    const { workInfo } = this.state;
    return (
      <div id="work-detail" className="embed">
        <CastViewer workInfo={workInfo} {...this.props} />
      </div>
    );
  }
}

function mapStateToProps(state) {
  const { Root } = state;
  const isMobile = Root.isMobile;
  return { isMobile };
}

function buildActionDispatcher(dispatch) {
  return {
    workAction: bindActionCreators(workAction, dispatch),
  };
}
